package com.fz.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fz.entity.Fee;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Param;
import java.time.LocalDateTime;

/**
 * <p>
 * 存储水电使用账单信息 Mapper 接口
 * </p>
 *
 * @author hyr
 * @since 2025-06-22
 */
public interface FeeMapper extends BaseMapper<Fee> {
    // 获取每日用量统计
    @Select("SELECT DATE(create_time) AS date, type, SUM(consumed) AS total_consumed " +
            "FROM fee " +
            "WHERE user_id = #{userId} AND create_time >= CURDATE() - INTERVAL 30 DAY " +
            "GROUP BY DATE(create_time), type")
    List<Map<String, Object>> getDailyConsumption(@Param("userId") Long userId);

    // 获取费用类型分布
    @Select("SELECT type, SUM(amount) AS total_amount " +
            "FROM fee " +
            "WHERE user_id = #{userId} " +
            "GROUP BY type")
    List<Map<String, Object>> getFeeDistribution(@Param("userId") Long userId);
}